/*
 * @Description: 
 * @Version: 
 * @Autor: tangwc
 * @Date: 2023-05-02 22:11:12
 * @LastEditors: tangwc
 * @LastEditTime: 2023-05-03 13:18:14
 * @FilePath: \stm32_lvgl8.3_demo\User\tp_driver\cst816t.c
 * 
 *  Copyright (c) 2023 by tangwc, All Rights Reserved. 
 */
#include <stdio.h>

#include "tp_i2c.h"
#include "cst816t.h"


uint8_t cst816t_chipId(void)
{
    uint8_t id = 0;
    uint8_t res = 0;
    res = tp_i2c_read_len(0xA7, &id, 1);

    printf("touch chip: CST816T======%d===========%d\n", id, res);

    return 0;
}

static uint8_t cst816t_get_touch_points_num(uint8_t *touch_points_num)
{
    uint8_t res = 0;
    res = tp_i2c_read_len(0x02, touch_points_num, 1);
    return res;
}

void cst816t_read_pos(uint8_t *touch_points_num, uint16_t *x, uint16_t *y)
{
    uint8_t data[4];

    cst816t_get_touch_points_num(touch_points_num);
    printf("touch_points_num:%d\n", *touch_points_num);
    if (0 == *touch_points_num)
    {
        *x = 0;
        *y = 0;
        return;
    }
    else
    {
        tp_i2c_read_len(0x03, data, 4);

        *x = ((data[0] & 0x0f) << 8) | data[1];
        *y = ((data[2] & 0x0f) << 8) | data[3];

        printf("pos:===========X:%d==========Y:%d\n", *x,*y);
    }
}
